package com.example.testgit.mapstruct;

import com.example.testgit.VO.PunishmentVO;
import com.example.testgit.entity.PunishmentDO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @author: lyh
 * @create: 2023/5/8 22:39
 * Description：
 */
@Mapper
public interface PunishmentConverter {
    PunishmentConverter INSTANCE = Mappers.getMapper(PunishmentConverter.class);

    @Mappings({
            @Mapping(source = "punishType", target = "punishType", qualifiedByName = "punishTrans"),
            @Mapping(source = "punishTime", target = "punishTime", dateFormat = "yyyy-MM-dd")
    })
    PunishmentVO toVO(PunishmentDO punishmenDO);

    @Mappings({
            @Mapping(source = "punishType", target = "punishType", qualifiedByName = "punishTrans"),
            @Mapping(source = "punishTime", target = "punishTime", dateFormat = "yyyy-MM-dd")
    })
    List<PunishmentVO> toVOList(List<PunishmentDO> punishmentDOList);

    @Named("punishTrans")
    default String punishTrans(Integer punishType) {
        if (punishType.equals(0)) return "警告";
        else if (punishType.equals(1)) return "记过";
        else if (punishType.equals(2)) return "严重警告";
        else return "留校察看";
    }
}
